from django.test import TestCase


if __name__ == '__main__':
    import os
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ShopSystem.settings')
    import django
    django.setup()

    from django.core.mail import send_mail
    from JiXuShopSystem import settings
    from users.utils import generate_verify_email_url
    from itsdangerous import TimedJSONWebSignatureSerializer as TJ
    email = '1529063814@qq.com'

    # 发送邮箱
    subject = '几许商城邮箱验证'
    # 调用生成加密验证邮箱连接
    data = {
        'id': 1,
        'email': email
    }
    # 进行加密
    s = TJ(settings.SECRET_KEY, 600)  # 加密方法 , 有效时间
    token = s.dumps(data)
    # 获得加密链接
    veerify_url = settings.EMAIL_VERIFY_URL + "?token=" + token.decode()



    html_message = f'<p>您的邮箱为：{email} , 请点击链接进行验证激活邮箱</p>' \
                   f'<p><a href="{veerify_url}">{veerify_url}</p>'
    send_mail(subject, '', from_email=settings.EMAIL_FROM,
              recipient_list=[email], html_message=html_message)